package com.eclink.asset.workflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eclink.asset.common.domain.CommonResult;
import com.eclink.asset.domain.AuditProcess;
import com.eclink.asset.pojo.query.AssetAuditConfigQuery;
import com.eclink.asset.workflow.service.AuditConfigService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资产审批配置接口Controller
 *
 * @author chenshixian
 * @date 2024-06-04
 */
@Api(tags="审批流程接口列表")
@RestController
@RequestMapping("/auditProcess")
public class AuditProcessController extends BaseController {

    @Resource
    private AuditConfigService service;

    @ApiOperation("查询")
    @PostMapping("/list")
    public ResponseEntity<Page<AuditProcess>> list(@RequestBody AssetAuditConfigQuery query, Pageable page, Integer configType) {
        IPage<AuditProcess> pageData = service.selectList(query, page, configType);
        List<AuditProcess> list = pageData.getRecords();
        return ResponseEntity.ok(new PageImpl<>(list, page, pageData.getTotal()));
    }

    @ApiOperation("获取资产审批配置详细信息")
    @GetMapping(value = "/{id}")
    public ResponseEntity<AuditProcess> getInfo(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("新增资产审批配置")
    @Log(title = "资产审批配置", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody AuditProcess auditProcess) {
        return ResponseEntity.ok(service.insert(auditProcess));
    }

    @ApiOperation("修改资产审批配置")
    @Log(title = "资产审批配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody AuditProcess auditProcess) {
        return ResponseEntity.ok(service.update(auditProcess));
    }

    @ApiOperation("查询流程的节点数")
    @GetMapping("getNodeCount/{id}")
    public ResponseEntity<Integer> getNodeCount(@PathVariable Long id) {
        int res = service.getNodeCount(id);
        return ResponseEntity.ok(res);
    }

    @ApiOperation("修改状态")
    @PutMapping("updateStatus")
    public ResponseEntity<Integer> updateStatus(@RequestBody AuditProcess auditProcess) {
        int res = service.updateStatus(auditProcess);
        return ResponseEntity.ok(res);
    }

    @ApiOperation("删除资产审批配置")
    @Log(title = "资产审批配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
